#ifndef CONFIG_H
#define CONFIG_H

#include "tlist.h"
#include "host.h"
#include "broadcast.h"

#define CFG_ALL			0xffffffff
#define CFG_GENERAL		0x00000001
#define CFG_ABSENCE		0x00000002
#define CFG_WINSIZE		0x00000004
#define CFG_FONT		0x00000008
#define CFG_BROADCAST	0x00000010
#define CFG_CLICKURL	0x00000020
#define CFG_PRIORITY	0x00000040
#define CFG_FINDHIST	0x00000080
#define CFG_HOSTINFO	0x00001000
#define CFG_DELHOST		0x00002000
#define CFG_DELCHLDHOST	0x00004000
#define CFG_CRYPT		0x00008000

enum SendWidth { SW_NICKNAME, SW_ABSENCE, SW_GROUP, SW_HOST, SW_IPADDR, SW_USER, SW_PRIORITY, MAX_SENDWIDTH };
inline BOOL GetItem(UINT columnItems, int sw) { return (columnItems & (1 << sw)) ? TRUE : FALSE; }
inline void SetItem(UINT *columnItems, int sw, BOOL on) { if (on) *columnItems |= (1 << sw); else *columnItems &= ~(1 << sw); }

class TRegistry;

struct TCfg
{
public:
	TCfg( ULONG nicAddr, int portNum );
	~TCfg();

public:
	CHosts	priorityHosts;
	CHosts	fileHosts;
	int		priorityMax;
	int		priorityReject;
	char**	prioritySound;

	ULONG	nicAddr;
	int		portNum;
	int		lcid;
	BOOL	noPopupChek;
	BOOL	openCheck;
	BOOL	noErase;
	BOOL	noBeep;
	BOOL	oneClickPopup;
	BOOL	balloonNotify;
	int		delayTime;
	BOOL	logCheck;
	BOOL	logUTF8;
	char	logFile[MAX_PATH];
	char	soundFile[MAX_PATH];
	BOOL	absenceSave;
	BOOL	absenceCheck;
	int		absenceMax;
	int		absenceChoice;
	char	(*absenceStr)[MAX_PATH];
	char	(*absenceHead)[MAX_NAMEBUF];

	int		findMax;
	char	(*findStr)[MAX_NAMEBUF];
	BOOL	findAll;

	HCRYPTPROV	smallCsp;
	PubKey		smallPubKey;
	HCRYPTKEY	smallPrivKey;

	HCRYPTPROV	hCsp;
	PubKey		pubKey;
	BYTE*		privBlob;
	int			privBlobLen;
	int			privEncryptType;
	BYTE*		privEncryptSeed;
	int			privEncryptSeedLen;
	HCRYPTKEY	privKey;

	BOOL	quoteCheck;
	BOOL	secretCheck;
	BOOL	ipAddrCheck;
	BOOL	hotKeyCheck;
	int		hotKeyModify;
	int		hotKeySend;
	int		hotKeyRecv;
	int		hotKeyMisc;
	BOOL	controlIME;
	int		glidLineCheck;
	UINT	columnItems;
	BOOL	allowSendList;
	int		fileTransOpt;
	int		resolveOpt;
	int		encryptNum;

	int		viewMax;
	int		transMax;
	int		tcpBufMax;
	BOOL	lumpCheck;

	int		nickNameCheck;
	char	nickNameStr[MAX_NAMEBUF];
	char	groupNameStr[MAX_NAMEBUF];
	BOOL	abnormalButton;
	BOOL	absenceNonPopup;
	BOOL	listGet;
	UINT	listGetMSec;
	UINT	retryMSec;
	UINT	retryMax;
	int		recvMax;
	char	iconFile[MAX_PATH];
	char	revIconFile[MAX_PATH];
	char	lastSaveDir[MAX_PATH];
	char	lastOpenDir[MAX_PATH];
	ULONG	sort;
	int		updateTime;
	int		keepHostTime;
	BOOL	msgMinimize;
	BOOL	defaultUrl;
	BOOL	shellExec;
	BOOL	extendEntry;
	char	quoteStr[MAX_NAMEBUF];
	BOOL	debug;

	int		sendWidth[MAX_SENDWIDTH];
	int		sendOrder[MAX_SENDWIDTH];

	int		sendXDiff;
	int		sendYDiff;
	int		sendMidYDiff;
	BOOL	sendSavePos;
	int		sendXPos;
	int		sendYPos;

	int		recvXDiff;
	int		recvYDiff;
	BOOL	recvSavePos;
	int		recvXPos;
	int		recvYPos;

	LOGFONT sendEditFont;
	LOGFONT	sendListFont;
	LOGFONT	recvHeadFont;
	LOGFONT	recvEditFont;

	char	pswdStr[MAX_NAMEBUF];
	BOOL	pswdLogCheck;
	CList	urlList;
	BOOL	dialUpCheck;
	CList	dialUpList;
	CBroadcastList	broadcastList;

	enum PART{ FIND };

	bool ReadRegistry(void);
	bool WriteRegistry( int ctlFlag = CFG_ALL );
	void GetRegName( char* buf, ULONG nicAddr, int portNum );

protected:
	bool ReadFontRegistry( TRegistry* reg, char* key, LOGFONT* font );
	bool WriteFontRegistry(TRegistry* reg, char* key, LOGFONT* font );
};

#endif	// CONFIG_H